home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-10-26 | 1.5 KB | 35 lines | [TEXT/$Tcl] |
-
-
- dup fileId ?targetFileId?
- Duplicate an open file. A new file id is opened that
- addresses the same file as fileId.
-
- If targetFileId is specified, the the file is dup to
- this specified file id. Normally this is stdin,
- stdout, or stderr. The dup command will handle flush-
- ing output and closing this file. It is recommended
- that the file not be closed in advanced if it is one of
- stdin, stdout, or stderr. Otherwise internal C code
- that uses one of these files via direct access to stdio
- FILE struct may fail.
-
- The procedure shown below will create a child process
- and set its standard input and output files to a pair
- of pipe files we pass as arguments. Finally the pro-
- gram does an execl of a specified command, with the
- program's stdin and stdout coming from and going to our
- pair of pipes.
-
- proc ChildProcess {cmd inPipe outPipe} {
- if {[set childPid [fork]] == 0} {
- dup $inPipe stdin
- close $inPipe
- dup $outPipe stdout
- close $outPipe
-
- execl $cmd
- # will never make it here...
- }
- return $childPid
- }
-